package com.pay.merchant.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.pay.entity.BankDetail;
import com.pay.entity.BankType;
import com.pay.entity.CashDetails;
import com.pay.entity.MerchantAccount;
import com.pay.entity.MerchantAccountDetail;
import com.pay.merchant.mapping.MappingUtils;
import com.pay.service.IBankDetailService;
import com.pay.service.IBankTypeService;
import com.pay.service.ICashDetailsService;
import com.pay.service.IMerchantAccountDetailService;
import com.pay.service.IMerchantAccountService;
import com.pay.utils.BasePage;
import com.pay.utils.ResponseData;

@Controller
public class FinanceController {
	
	@Autowired
	private IBankTypeService bankTypeService ;
	
	@Autowired
	private IBankDetailService bankDetailService ;
	
	@Autowired
	private ICashDetailsService cashDetailsService ;
	
	@Autowired
	private IMerchantAccountService merchantAccountService ;
	
	@Autowired
	private IMerchantAccountDetailService merchantAccountDetailService ;
	
	@RequestMapping(value=MappingUtils.showMoneyDetailList)
	public ModelAndView showMoneyDetailList(MerchantAccountDetail merchantAccountDetail,BasePage<MerchantAccountDetail> page,Integer loginId) {
		merchantAccountDetail.setMerId(loginId);
		merchantAccountDetailService.getList(merchantAccountDetail, page);
		MerchantAccount account = merchantAccountService.getByMerId(loginId);
		ModelAndView m = new ModelAndView(MappingUtils.showMoneyDetailList);
		m.addObject("merchantAccountDetail", merchantAccountDetail) ;
		m.addObject("loginId", loginId) ;
		m.addObject("list", page) ;
		m.addObject("account", account) ;
		return m ; 
	}
	
	@RequestMapping(value=MappingUtils.showBankManager)
	public ModelAndView showBankManager(BankDetail bankDetail,BasePage<BankDetail> page,Integer loginId) {
		bankDetail.setMerid(loginId); 
		bankDetailService.getList(bankDetail,page) ;
		ModelAndView m = new ModelAndView(MappingUtils.showBankManager);
		m.addObject("bankDetail", bankDetail) ;
		m.addObject("loginId", loginId) ;
		m.addObject("list", page) ;
		return m ; 
	}
	
	@RequestMapping(value=MappingUtils.showBankAdd)
	public ModelAndView showBankAdd(Integer loginId) {
		List<BankType> bankTypeList = bankTypeService.list(null);
		ModelAndView m = new ModelAndView(MappingUtils.showBankAdd);
		m.addObject("loginId", loginId) ;
		m.addObject("bankTypeList", bankTypeList) ;
		return m ; 
	}
	
	@ResponseBody
	@RequestMapping(value=MappingUtils.doBankAdd)
	public ResponseData doBankAdd(BankDetail bankDetail,Integer loginId) {
		bankDetail.setMerid(loginId);
		return bankDetailService.doBankAdd(bankDetail) ;
	}
	
	@RequestMapping(value=MappingUtils.showBankEdit)
	public ModelAndView showBankEdit(Integer id,Integer loginId) {
		BankDetail bankDetail = bankDetailService.getById(id);
		ModelAndView m = new ModelAndView(MappingUtils.showBankEdit);
		List<BankType> bankTypeList = bankTypeService.list(null);
		m.addObject("loginId", loginId) ;
		m.addObject("bankTypeList", bankTypeList) ;
		m.addObject("bankDetail", bankDetail) ;
		return m ; 
	}
	
	@ResponseBody
	@RequestMapping(value=MappingUtils.doBankEdit)
	public ResponseData doBankEdit(BankDetail bankDetail) {
		return bankDetailService.doBankEdit(bankDetail) ;
	}
	
	@RequestMapping(value=MappingUtils.showCashManager)
	public ModelAndView showCashManager(CashDetails cashDetails,BasePage<CashDetails> page,Integer loginId) {
		cashDetails.setMerid(loginId);
		cashDetailsService.getList(cashDetails,page) ;
		ModelAndView m = new ModelAndView(MappingUtils.showCashManager);
		m.addObject("loginId", loginId) ;
		m.addObject("list", page) ;
		m.addObject("cashDetails", cashDetails) ;
		return m ; 
	}
	
	@RequestMapping(value=MappingUtils.showCashAdd)
	public ModelAndView showCashAdd(Integer loginId) {
		BankDetail bankDetail = new BankDetail();
		bankDetail.setMerid(loginId);
		BasePage<BankDetail> page = new BasePage<BankDetail>();
		page.setPage(false);
		bankDetailService.getList(bankDetail, page);
		ModelAndView m = new ModelAndView(MappingUtils.showCashAdd);
		m.addObject("loginId", loginId) ;
		m.addObject("bankDetailList", page.getRecords()) ;
		return m ;
	}
	
	@ResponseBody
	@RequestMapping(value=MappingUtils.doCash)
	public ResponseData doCash(CashDetails cashDetail,Integer loginId) {
		cashDetail.setMerid(loginId);
		return cashDetailsService.doCash(cashDetail) ;
	}
}
